﻿using System;
using System.Numerics;

class Tribonachi
{
    static void Main()
    {
        string input = Console.ReadLine();
        BigInteger first = int.Parse(input);
        input = Console.ReadLine();
        BigInteger second = int.Parse(input);
        input = Console.ReadLine();
        BigInteger third = int.Parse(input);
        input = Console.ReadLine();
        int n = int.Parse(input);
        BigInteger temp = 0;

        for (int i = 0; i < n-3; i++)
        {
            temp = first + second + third;
            first = second;
            second = third;
            third = temp;
        }
        Console.WriteLine(third);
    }
}